<?php

/**
 * Part form base class.
 *
 * @method Part getObject() Returns the current form's model object
 *
 * @package    Porba
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BasePartForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'            => new sfWidgetFormInputHidden(),
      'part_number'   => new sfWidgetFormInputText(),
      'name'          => new sfWidgetFormInputText(),
      'type'          => new sfWidgetFormInputText(),
      'description'   => new sfWidgetFormTextarea(),
      'VAT'           => new sfWidgetFormInputText(),
      'price'         => new sfWidgetFormInputText(),
      'unit'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('MaterialUnits'), 'add_empty' => true)),
      'stock'         => new sfWidgetFormInputText(),
      'min_stock'     => new sfWidgetFormInputText(),
      'reserved'      => new sfWidgetFormInputText(),
      'in_production' => new sfWidgetFormInputText(),
      'location'      => new sfWidgetFormInputText(),
      'ordered'       => new sfWidgetFormInputText(),
      'created_at'    => new sfWidgetFormDateTime(),
      'updated_at'    => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'            => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'part_number'   => new sfValidatorInteger(),
      'name'          => new sfValidatorString(array('max_length' => 255)),
      'type'          => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'description'   => new sfValidatorString(array('max_length' => 4000, 'required' => false)),
      'VAT'           => new sfValidatorNumber(array('required' => false)),
      'price'         => new sfValidatorNumber(array('required' => false)),
      'unit'          => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('MaterialUnits'), 'required' => false)),
      'stock'         => new sfValidatorNumber(),
      'min_stock'     => new sfValidatorNumber(),
      'reserved'      => new sfValidatorNumber(),
      'in_production' => new sfValidatorNumber(),
      'location'      => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'ordered'       => new sfValidatorInteger(),
      'created_at'    => new sfValidatorDateTime(),
      'updated_at'    => new sfValidatorDateTime(),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorDoctrineUnique(array('model' => 'Part', 'column' => array('part_number')))
    );

    $this->widgetSchema->setNameFormat('part[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'Part';
  }

}
